package com.liangtian.mdm.dm.jsp.common;

import com.liangtian.mdm.dm.common.constant.TableConst;
import com.liangtian.mdm.dm.common.constant.UrlConst;
import com.liangtian.mdm.dm.common.enums.Type;
import com.liangtian.mdm.dm.config.model.AttrConfig;
import com.liangtian.mdm.dm.group.model.AttrGroup;
import com.liangtian.mdm.dm.model.model.Model;
import com.liangtian.mdm.util.ConstantBean;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AddJsCreate {
    /**
     * * <p>Title: 动态拼接新增js模板替换</p>
     *
     * @author : xiaoliu
     * @date :2016年8月8日下午2:26:36
     */
    @SuppressWarnings("unchecked")
    public static void createAddJs(Map<String, Object> res_Map, String readFilePath,
                                   Model model, Map<String, Object> resMap, String operType, String appLy,
                                   Map<String, Object> result_map, Model mainModel, List<AttrGroup> groupLst) {
        try {
            
            String script = JspUtil.replaceStr(readFilePath, model, operType); // 每个列表页面的js都要替换的内容
            List<String> columList = (List<String>) res_Map.get("columList");//columList判断是否有选择设置的列
            List<AttrConfig> attributeRadioList = (List<AttrConfig>) resMap.get("attributeRadioList");//所有单选按钮对象
            List<AttrConfig> attributeCheckboxList = (List<AttrConfig>) resMap.get("attributeCheckboxList");//所有复选框对象
            List<AttrConfig> fileLst = (List<AttrConfig>) resMap.get("fileLst");
            //拼写多附件增加方法
            if (fileLst.isEmpty()) {
                script = script.replace("{addFilesFun}", "");
            } else {
                script = script.replace("{addFilesFun}", spellAddFiles(fileLst));
            }
            List<AttrConfig> selectList = (List<AttrConfig>) resMap.get("selectList");//所有级联下拉框对象

            if (columList.size() == 0 && columList.isEmpty()) {
                script = script.replace("{checkNgShow}", "submitData();");
            } else {
                script = script.replace("{checkNgShow}", JspUtil.spellNgShow(columList, attributeRadioList, attributeCheckboxList));
            }

//				 if(columList.size()==0 && columList.isEmpty()){
//					 if("0".equals(model.getTableName())){//表示是主数据
//						 script = script.replace("{checkNgShow}", "var flag = checkAddForum(); if(flag){  submitData();  }"); 
//					 }else{
//						 script = script.replace("{checkNgShow}", "submitData();");
//					 }
//				 }else{
//					  script = script.replace("{checkNgShow}", JspUtil.spellNgShow(model,columList,attributeRadioList,attributeCheckboxList));
//				}
//			}else{//表示是字典
//				     if(columList.size()==0 && columList.isEmpty()){
//			           script = script.replace("{checkNgShow}", "submitData();");
//					 }else{
//						 script = script.replace("{checkNgShow}", JspUtil.spellNgShow(model,columList,attributeRadioList,attributeCheckboxList));
//					 }
//			}
            // 选择设置
            String fun = (String) res_Map.get("sb");
            if (null != fun && !"".equals(fun)) {
                script = script.replace("{ngShowFunction}", fun);
            } else {
                script = script.replace("{ngShowFunction}", "");
            }

            // 自定义编码
            String autoCode = (String) res_Map.get("autoCode");
            if (null != autoCode && !"".equals(autoCode)) {
                script = script.replace("{autoCodeFunction}", autoCode);
            } else {
                script = script.replace("{autoCodeFunction}", "");
            }

            Map<String, String> SubMap = spellAddReturnResult(true, model, appLy, operType, result_map);
            script = script.replace("{successShow}", SubMap.get("sb"));
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
                script = script.replace("{returnApplyUrl}",
                        "'/am/" + model.getTableName() + "/" + model.getTableName() + "_" + appLy + ".jsp?mainId='+$('#mainId').val()");
            } else if ("0".equals(model.getClassType()) && "0".equals(model.getModelType())) {//主数据--列表
                script = script.replace("{returnApplyUrl}",
                        "'/am/" + model.getTableName() + "/" + model.getTableName() + "_" + appLy + ".jsp'");
            } else {
                script = script.replace("{returnApplyUrl}",
                        "'/am/" + model.getTableName() + "/" + model.getTableName() + "_" + appLy + ".jsp?" + JspUtil.spellColumn(model, Type.MAIN) + "='+$('#" + JspUtil.spellColumn(model, Type.ADD) + "').val()");
            }
            //根据表单元素（input[type='text',type='file'],文本域，下拉框）值一变化解除新增保存按钮的禁用
            script = script.replace("{spellFormElementChange}", spellFormElementChangeFun());
            //
            script = script.replace("{bodyApp}", model.getTableName());
            script = script.replace("{bodyApp}", model.getTableName()); //
            script = script.replace("{bodyCtr}", model.getTableName()); //
            script = script.replace("{formId}", model.getTableName()); //
            script = script.replace("{formName}", model.getTableName()); //
            script = script.replace("{tableName}", model.getTableName());
            script = script.replace("{treeId}", model.getTableName() + "tree");
            script = script.replace("{title}", model.getModelName()); //
            script = script.replace("{submitUrl}", UrlConst.INSERTURL);
            script = script.replace("{treeSearchURL}", UrlConst.TREENODESURL);
            // 这里动态拼接数据库查询出来的数据参数，新增数据的参数，显示列名称
            List<AttrConfig> configLst = (List<AttrConfig>) resMap.get("jspAttrLst");
            script = script.replace("{getIsMoreViewApply}", getIsMoreViewApply(model, groupLst));
            script = script.replace("{getIsMoreClearAttrs}", getIsMoreClearAttrs(model, groupLst, configLst));
            script = script.replace("{checkColumnsAdd}", checkColumnsAdd(model, configLst, groupLst, operType));
            //判断是否含有唯一校验
            //	script = script.replace("{checkColumnIsShow}",checkColumnIsShow(configLst));
            //唯一性校验方法
            //script = script.replace("{checkWeiYiColumn}",checkWeiYiColumn(configLst,model,operType));
            //	script = script.replace("{spellWeiYiMethod}",spellWeiYiMethod(configLst));
            script = script.replace("{callAutoCodeFunction}", CodeBlock.callAutoCodeFunction(configLst));

            script = script.replace("{submitparams}",
                    (String) AddJsCreate.createAddParams(mainModel, model, operType, configLst, groupLst).get("sb"));

            script = script.replace("{popValues}",
                    (String) AddJsCreate.createAddPOPParams(model, configLst).get("sb"));
            // 这里拼接pop获取参数值得方法
            script = script.replace("{treeValues}",
                    (String) AddJsCreate.createAddTreeParams(model, configLst).get("sb"));
            // 这里加载动态拼接selectList JS的拼接方法
            Map<String, Object> map = AddJsCreate.spellJsAddStr(operType, model, configLst);
            script = script.replace("{selectList}", (String) map.get("sb"));
            //获取selectFlag  true-说明是select下拉框，组件类型是关联关系
            boolean selectFlag = (boolean) map.get("selectFlag");
            if (selectFlag) {
                //selectMap--（"C_003"--列名,"attrconfig" --对象）
                /*级联关系这需要再次修改，从前的三级级联--国家--省份--城市，
                 * 目前满足不了用户需求，所以，打算放开，用户设置成几次级联，就几次级联
                 * 刘晶   2017/06/21 针对万达系统开发（更改级次问题）
                 * */
                Map<String, Map<String, AttrConfig>> selectMap = (Map<String, Map<String, AttrConfig>>) resMap.get("selectMap");
                script = script.replace("{selectClickFunction}", JspUtil.spellSelectClick(operType, model, selectMap));
            } else {
                script = script.replace("{selectClickFunction}", "");
            }

            boolean rcFlag = (boolean) resMap.get("flag");//是否有单选框或者复选框类型的属性
            if (rcFlag) {
                script = script.replace("{checkRadioOrCheckboxIsNull}", JspUtil.createCheckFunction(operType, attributeRadioList, attributeCheckboxList));
                script = script.replace("{spellRadioValueChange}", spellRadioValueChangeFun(attributeRadioList, attributeCheckboxList, selectList));
            } else {
                script = script.replace("{checkRadioOrCheckboxIsNull}", "");
                script = script.replace("{spellRadioValueChange}", "");
            }

            JspUtil.writeInJsp(script, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String spellAddFiles(List<AttrConfig> fileLst) {
        StringBuffer sb = new StringBuffer();
        String colum = null;
        for (AttrConfig ac : fileLst) {
            colum = ac.getAttrColumn().toLowerCase();
            sb.append("var " + colum + "index = 1; \r\n")
                    .append("$('#" + colum + "Button').click(function (){ \r\n")
                    .append("    	$('#" + colum + "files').append(\" <div class='form-group draggable' id='" + colum + "_\"+" + colum + "index+\"Div' > \" +  \r\n")
                    .append("     \"  <label class='col-sm-3 control-label'>" + ac.getAttrName() + "\"+" + colum + "index+" + "\"</label> \" + \r\n")
                    .append("     \"  <div class='col-sm-5' > \" + \r\n")
                    .append("	 		\"       <input type='file' id='" + colum + "_\"" + "+" + colum + "index+" + "\"" + "' name='" + colum + "_\"" + "+" + colum + "index+" + "\"" + "' ng-model='" + colum + "' class='form-control'> \" + \r\n")
                    .append("     \" </div> \" + \r\n")
                    .append("     \" <div class='btn2'> \" + \r\n")
                    .append("         \"       <button type='button' id='" + colum + "_\"" + "+" + colum + "index+" + "\"" + "Button' class='btn btn-outline btn-default'> \"+      \r\n")
                    .append("         \"            删除  \"+ \r\n")
                    .append("         \"       </button> \" + \r\n")
                    .append("    \"  </div> \"+  \r\n")
                    .append("   \" </div> \" ) \r\n")
                    .append(" \r\n")
                    .append(" " + colum + "index++; \r\n")
                    .append("}) \r\n")
                    .append("\r\n").append("\r\n")
                    .append("$('#" + colum + "files').on('click','.btn2',function(){  \r\n")
                    .append("    $(this).parent().remove(); \r\n")
                    .append(" }) \r\n");
        }
        return sb.toString();
    }

    public static Map<String, String> spellEditReturnResult(boolean fileFlag, Model model, String appLy, String operType, Map<String, Object> result_map) {
        String tableName = model.getTableName();
        StringBuilder sb = new StringBuilder();

        if (fileFlag) {
            sb.append("     if(2==data.data){ $RN$");
            sb.append("          toastr.error('上传文件失败!'); $RN$");
            sb.append("           $('#saveButton').attr('disabled',true); $RN$");
            sb.append("          return; $RN$");
            sb.append("     }else if(1==data.data){ $RN$");
            sb.append("           toastr.success('操作数据成功!'); $RN$");
        } else {
            sb.append("     if(1==data.data){ $RN$");
            sb.append("           toastr.success('操作数据成功!'); $RN$");
        }
        if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
            sb.append("           setTimeout(function() { $RN$");
            sb.append("                 location.href=basePath+'/am/" + tableName + "/" + tableName + "_" + appLy + ".jsp?mainId='+$('#mainId').val(); $RN$");
            sb.append("           }, 500); $RN$");
            sb.append("      }else{ $RN$");
            sb.append("            toastr.error('操作数据失败!'); $RN$");
            sb.append("           $('#saveButton').attr('disabled',true); $RN$");
            sb.append("     } $RN$");
        } else {
            boolean Nflag = (boolean) result_map.get("flag");
            if (Nflag) {
                List<Model> subModelLst = (List<Model>) result_map.get("subModel");
                sb.append("	 $('#saveButton').attr('disabled',true); $RN$");
                if ("edit".equals(operType) || "treeTabEdit".equals(operType)) {
                    for (int i = 0; i < subModelLst.size(); i++) {
                        Model subTable = subModelLst.get(i);
                        sb.append("   $('#" + subTable.getTableName() + operType + "Frame').attr('src',basePath+'/am/" + subTable.getTableName() + "/" + subTable.getTableName() + "_apply.jsp?mainId='+$scope.id); $RN$");
                    }
                } else if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
                    for (int i = 0; i < subModelLst.size(); i++) {
                        Model subTable = subModelLst.get(i);
                        sb.append("   $('#" + subTable.getTableName() + operType + "Frame').attr('src',basePath+'/am/" + subTable.getTableName() + "/" + subTable.getTableName() + "_update.jsp?mainId='+$scope.updateId); $RN$");
                    }
                } else {
                    sb.append("   $scope.mId=data.msg; $RN$");
                    for (int i = 0; i < subModelLst.size(); i++) {
                        Model subTable = subModelLst.get(i);
                        sb.append("   $('#" + subTable.getTableName() + operType + "Frame').attr('src',basePath+'/am/" + subTable.getTableName() + "/" + subTable.getTableName() + "_apply.jsp?mainId='+$scope.mId); $RN$");
                    }
                }
            } else {
                sb.append("    setTimeout(function() { $RN$");
                sb.append(EditJsCreate.getEditReturnMainPath(model, appLy));
//				sb.append("     location.href=basePath+'/am/"+tableName+"/"+tableName+"_"+appLy+".jsp'; $RN$");
//				"     location.href=basePath+'/am/"+tableName+"/"+tableName+"_"+appLy+".jsp'; $RN$"
                sb.append("    }, 500); $RN$");
            }
            sb.append("   }else{ $RN$");
            sb.append("       toastr.error('操作数据失败!'); $RN$");
            sb.append("       $('#saveButton').attr('disabled',true); $RN$");
            sb.append("   } $RN$");
        }
        Map<String, String> resMap = new HashMap<String, String>();
        resMap.put("sb", sb.toString().replace("$RN$", "\r\n"));
        return resMap;
    }


    public static Map<String, String> spellAddReturnResult(boolean fileFlag, Model model, String appLy, String operType, Map<String, Object> result_map) {
        String tableName = model.getTableName();
        StringBuilder sb = new StringBuilder();

        if (fileFlag) {
            sb.append("     if(2==data.data){ $RN$");
            sb.append("           toastr.error('上传文件失败!'); $RN$");
            sb.append("            $('#saveButton').attr('disabled',true); $RN$");
            sb.append("         return; $RN$");
            sb.append("     }else if(1==data.data){ $RN$");
            sb.append("         toastr.success('操作数据成功!'); $RN$");
        } else {
            sb.append("    if(1==data.data){ $RN$");
            sb.append("           toastr.success('操作数据成功!'); $RN$");
        }
        if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
            sb.append("     setTimeout(function() { $RN$");
            sb.append("          location.href=basePath+'/am/" + tableName + "/" + tableName + "_" + appLy + ".jsp?mainId='+$('#mainId').val(); $RN$");
//			EditJsCreate.getEditReturnPath(model, appLy)
//			
            sb.append("       }, 500); $RN$");
            sb.append("     }else{ $RN$");
            sb.append("        toastr.error('操作数据失败!'); $RN$");
            sb.append("        $('#saveButton').attr('disabled',true); $RN$");
            sb.append("     } $RN$");
        } else {
            boolean Nflag = (boolean) result_map.get("flag");
            if (Nflag) {
                List<Model> subModelLst = (List<Model>) result_map.get("subModel");
                sb.append("	 $('#saveButton').attr('disabled',true); $RN$");
                if ("edit".equals(operType) || "treeTabEdit".equals(operType)) {
                    for (int i = 0; i < subModelLst.size(); i++) {
                        Model subTable = subModelLst.get(i);
                        sb.append("   $('#" + subTable.getTableName() + operType + "Frame').attr('src',basePath+'/am/" + subTable.getTableName() + "/" + subTable.getTableName() + "_apply.jsp?mainId='+$scope.id); $RN$");
                    }
                } else if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
                    for (int i = 0; i < subModelLst.size(); i++) {
                        Model subTable = subModelLst.get(i);
                        sb.append("   $('#" + subTable.getTableName() + operType + "Frame').attr('src',basePath+'/am/" + subTable.getTableName() + "/" + subTable.getTableName() + "_update.jsp?mainId='+$scope.updateId); $RN$");
                    }
                } else {
                    sb.append("   $scope.mId=data.msg; $RN$");
                    for (int i = 0; i < subModelLst.size(); i++) {
                        Model subTable = subModelLst.get(i);
                        sb.append("   $('#" + subTable.getTableName() + operType + "Frame').attr('src',basePath+'/am/" + subTable.getTableName() + "/" + subTable.getTableName() + "_apply.jsp?mainId='+$scope.mId); $RN$");
                    }
                }
            } else {
                sb.append("   setTimeout(function() { $RN$");
//				sb.append(EditJsCreate.getEditReturnMainPath(model, appLy));
                if ("0".equals(model.getClassType())) {//列表
                    sb.append("       location.href=basePath+'/am/" + tableName + "/" + tableName + "_" + appLy + ".jsp'; $RN$");
                    //?"+ListJspCreate.spellMainColumn(model)+"='+"+ListJspCreate.spellEditColumn(model)+";
                } else {//父子树或者分类树
                    sb.append("       location.href=basePath+'/am/" + tableName + "/" + tableName + "_" + appLy + ".jsp?" + JspUtil.spellColumn(model, Type.MAIN) + "='+$('#" + JspUtil.spellColumn(model, Type.ADD) + "').val(); $RN$");
                }
//				"     location.href=basePath+'/am/"+tableName+"/"+tableName+"_"+appLy+".jsp'; $RN$"
                sb.append("    }, 500); $RN$");
            }
            sb.append("   }else{ $RN$");
            sb.append("       toastr.error('操作数据失败!'); $RN$");
            sb.append("       $('#saveButton').attr('disabled',true); $RN$");
            sb.append("   } $RN$");
        }
        Map<String, String> resMap = new HashMap<String, String>();
        resMap.put("sb", sb.toString().replace("$RN$", "\r\n"));
        return resMap;
    }

    /**
     * * <p>Title: 根据表单元素（input[type='text',type='file'],文本域，下拉框）值一变化解除新增保存按钮的禁用 </p>
     */
    public static String spellFormElementChangeFun() {
        StringBuffer sb = new StringBuffer();
        sb.append("$(document).ready(function () { $RN$");
        sb.append("   $(function () { $RN$");
        sb.append("       var jsonFormInit = $('#{formId}').serialize();$RN$");
        sb.append("       $('input[type=\"text\"],textarea, select').change(function () { $RN$");
        sb.append("          var jsonFormCurr = $('#{formId}').serialize();$RN$");
        sb.append("          if (jsonFormCurr != jsonFormInit) { $RN$");
        sb.append("              $('#saveButton').attr('disabled',false);$RN$");
        sb.append("          }else{ $RN$");
        sb.append("              $('#saveButton').attr('disabled',true);$RN$");
        sb.append("          } $RN$");
        sb.append("        });	$RN$");
        sb.append("       $('input[type=\"file\"]').change(function () { $RN$");
        sb.append("          if(document.getElementById('saveButton').disabled){ $RN$");
        sb.append("              $('#saveButton').attr('disabled',false); $RN$");
        sb.append("           } $RN$");
        sb.append("        }); $RN$");
        sb.append("    }); $RN$");
        sb.append("}); $RN$");
        return sb.toString().replace("$RN$", "\r\n");
    }


    /**
     * * <p>Title: 根据表单元素（input[type='radio']）值一变化解除新增保存按钮的禁用 </p>
     */
    public static String spellRadioValueChangeFun(List<AttrConfig> attributeRadioList, List<AttrConfig> attributeCheckboxList, List<AttrConfig> selectList) {
        StringBuffer sb = new StringBuffer();
        sb.append("   var settings_isChanged={}$RN$");
        //单选按钮
        if (selectList.size() > 0) {//所有级联下拉框
            for (int i = 0; i < selectList.size(); i++) {
                AttrConfig selectAttr = selectList.get(i);
                if (attributeRadioList.size() > 0) {
                    for (int j = 0; j < attributeRadioList.size(); j++) {
                        AttrConfig radioAttr = attributeRadioList.get(j);
                        if (!selectAttr.getCascadedAttr().equals(radioAttr.getAttrId())) {
                            String column = radioAttr.getAttrColumn().toLowerCase();
                            sb.append("   $scope.input" + column + "ValueIsChanged = function(eId) { $RN$");
                            sb.append("         $event = document.getElementById(''+eId+''); $RN$");
                            sb.append("         settings_isChanged[''+name] = false; $RN$");
                            sb.append("         if($event.type == 'radio'){ $RN$");
                            sb.append("             if($event.checked != $event.defaultChecked){ $RN$");
                            sb.append("                  settings_isChanged[''+name] = true;$RN$");
                            sb.append("             }$RN$");
                            sb.append("             if(isChanged()){$RN$");
                            sb.append("                  $('#saveButton').attr('disabled',false);$RN$");
                            sb.append("             }else{$RN$");
                            sb.append("                  $('#saveButton').attr('disabled',true);$RN$");
                            sb.append("             }$RN$");
                            sb.append("        }$RN$");
                            sb.append("    } $RN$");
                            sb.append("$RN$");
                        }
                    }
                }
            }
        } else {
            for (int j = 0; j < attributeRadioList.size(); j++) {
                AttrConfig radioAttr = attributeRadioList.get(j);
                String column = radioAttr.getAttrColumn().toLowerCase();
                sb.append("   $scope.input" + column + "ValueIsChanged = function(eId) { $RN$");
                sb.append("          $event = document.getElementById(''+eId+''); $RN$");
                sb.append("          settings_isChanged[''+name] = false; $RN$");
                sb.append("          if($event.type == 'radio'){ $RN$");
                sb.append("              if($event.checked != $event.defaultChecked){ $RN$");
                sb.append("                  settings_isChanged[''+name] = true;$RN$");
                sb.append("              }$RN$");
                sb.append("              if(isChanged()){$RN$");
                sb.append("                   $('#saveButton').attr('disabled',false);$RN$");
                sb.append("              }else{$RN$");
                sb.append("                   $('#saveButton').attr('disabled',true);$RN$");
                sb.append("              }$RN$");
                sb.append("          }$RN$");
                sb.append("    } $RN$");
                sb.append("$RN$");
            }
        }
        //复选按钮
//		if(attributeCheckboxList.size()>0){
//			for (int i = 0; i < attributeCheckboxList.size(); i++) {
//				AttrConfig checkAttr = attributeCheckboxList.get(i);
//				String  column = checkAttr.getAttrColumn().toLowerCase();
//								sb.append("    $scope.input"+column+"ValueIsChanged = function(eId) { $RN$");
//								sb.append("         $event = document.getElementById(''+eId+''); $RN$");
//								sb.append("         settings_isChanged[''+name] = false; $RN$");
//								sb.append("         if($event.type == 'radio'){ $RN$");
//								sb.append("              if($event.checked != $event.defaultChecked){ $RN$");
//								sb.append("                   settings_isChanged[''+name] = true;$RN$");
//								sb.append("              }$RN$");
//								sb.append("              if(isChanged()){$RN$");
//								sb.append("                   $('#saveButton').attr('disabled',false);$RN$");
//								sb.append("              }else{$RN$");
//								sb.append("                   $('#saveButton').attr('disabled',true);$RN$");
//								sb.append("              }$RN$");
//								sb.append("         }$RN$");
//								sb.append("    } $RN$");
//								sb.append("$RN$");
//			}
//
//		}

        sb.append(" function isChanged(){$RN$");
        sb.append("   for(var i in settings_isChanged){$RN$");
        sb.append("     if(settings_isChanged[i]){$RN$");
        sb.append("         return true;$RN$");
        sb.append("     }$RN$");
        sb.append("   }$RN$");
        sb.append(" }$RN$").append("$RN$");

        return sb.toString().replace("$RN$", "\r\n");
    }

    /**
     * * <p>Title: 动态拼接新增所传参数 </p>
     *
     * @author : xiaoliu
     * @date :2016年8月8日下午2:27:20
     */
    public static Map<String, Object> createAddParams(Model mainModel, Model model, String operType,
                                                      List<AttrConfig> configLst, List<AttrGroup> groupLst) {
        Map<String, Object> param = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        boolean isFile = false;
        for (int i = 0; i < configLst.size(); i++) {
            String column = configLst.get(i).getAttrColumn().toLowerCase();
            String attrType = configLst.get(i).getAttrType();
            if ("checkBoxType".equals(attrType)) {
                if ("add".equals(operType)) {
                    sb.append("'" + column + "':").append("$scope.").append(column).append(",");
                } else if ("edit".equals(operType) || "treeTabEdit".equals(operType) || "updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
                    sb.append("'flag" + column + "':").append("flag" + column).append(", ");
                }
            }
            if (attrType != null && "BLOB".equals(attrType))
                isFile = true;
        }

        String tableName = model.getTableName();
        if ("1".equals(model.getClassType())) {//说明是父子树
            sb.append("'pid':").append("$scope.pid,");
        }
        sb.append("'modelId':").append("'" + model.getId() + "',");

        if ("edit".equals(operType) || "treeTabEdit".equals(operType)) {
            sb.append("'tableName':").append("'" + tableName + "'");
            sb.append(",'operType':").append("'apply'");
//			sb.append(",'returnBase':").append("returnBase");
            if (isFile)
                sb.append(",'dataId':").append("$scope.id");
            param.put("attrConfigList", configLst);
        } else if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
            sb.append("'tableName':").append("'" + tableName + TableConst.MODIFYSUFFIX + "'");
            sb.append(",'operType':").append("'update'");
            if (isFile)
                sb.append(",'dataId':").append("$scope.updateId");
            param.put("attrConfigList", configLst);
        } else {
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
                if ("updateAdd".equals(operType)) {
                    sb.append("'tableName':").append("'" + tableName + TableConst.MODIFYSUFFIX + "',")
                            .append("'mainTableName':" + "'" + mainModel.getTableName() + TableConst.MODIFYSUFFIX + "',");
                    sb.append("'operType':").append("'update',");
                } else {
                    sb.append("'tableName':").append("'" + tableName + "',");
                    sb.append("'operType':").append("'apply',");
                }
                sb.append("'mainid':").append("$('#mainId').val()");
            } else {
                sb.append("'tableName':").append("'" + tableName + "',");
                sb.append("'operType':").append("'apply'");
            }
        }
        if (model.getIsMoreView() == 1) {//如果是多视图
            if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {//如果是变更编辑
                sb.append("");
            } else {
                sb.append(",'groupIds':").append("groupIds");
            }
        }
        param.put("sb", sb.toString());
        return param;
    }

    /**
     * * <p>Title: 动态拼接新增时，属性类型是弹出框时的参数拼接</p>
     *
     * @author : xiaoliu
     * @date :2016年8月8日下午2:27:58
     */
    public static Map<String, Object> createAddPOPParams(Model model, List<AttrConfig> configLst) {
        Map<String, Object> param = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < configLst.size(); i++) {
            String column = configLst.get(i).getAttrColumn().toLowerCase();
            // 新增操作
            if ("popList".equals(configLst.get(i).getAttrType())) {
                sb.append("     if(document.getElementById('" + column + "')){ $RN$");
                sb.append("          $scope.").append(column).append("=document.getElementById('" + column + "').value; $RN$");
                sb.append("      } $RN$");
            }
        }
        param.put("sb", sb.toString().replace("$RN$", "\r\n"));
        return param;
    }

    public static Map<String, Object> createAddTreeParams(Model model, List<AttrConfig> configLst) {
        Map<String, Object> param = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < configLst.size(); i++) {
            String column = configLst.get(i).getAttrColumn().toLowerCase();

            if ("listTree".equals(configLst.get(i).getAttrType())) {
                if (configLst.get(i).getIsDefaultParentType() == 1) {
                    sb.append("    if(document.getElementById('" + column + "')){ $RN$");
                    //sb.append("         $scope.").append(column).append("=document.getElementById('" + column + "').value; $RN$");
                    sb.append("        $scope.").append(column + "Name").append("=document.getElementById('" + column + "Name').value; $RN$");
                    sb.append("        $scope.").append(column).append("=document.getElementById('" + column + "').value; $RN$");
                    //sb.append("         $scope.pid=").append("$('#"+model.getTableName() + column.toUpperCase() +"treepid"+ "').val() || $scope.pid; $RN$");
                    sb.append("         $scope.pid=").append(" $scope." + column + " ");
                    sb.append("     } $RN$");
                } else {
                    sb.append("    if(document.getElementById('" + column + "')){ $RN$");
                    sb.append("        $scope.").append(column + "Name").append("=document.getElementById('" + column + "Name').value; $RN$");
                    sb.append("        $scope.").append(column).append("=document.getElementById('" + column + "').value; $RN$");
                    sb.append("    } $RN$");
                }
            }
        }
        param.put("sb", sb.toString().replace("$RN$", "\r\n"));
        return param;
    }

    /**
     * * <p>Title: 动态拼接新增js方法，查询数据</p>
     *
     * @author : xiaoliu
     * @date :2016年8月8日下午2:29:01
     */
    public static Map<String, Object> spellJsAddStr(String operType, Model model, List<AttrConfig> attrLst) {
        StringBuilder sb = new StringBuilder();// 将读取出来的数据，动态拼接成字符串
        boolean selectFlag = false;//是否有下拉框类型的属性
        String tableName = model.getTableName();

        List<String> popList = new ArrayList<String>();
        List<String> selectList = new ArrayList<String>();
        List<String> checkBoxList = new ArrayList<String>();
        List<String> fileList = new ArrayList<String>();
        List<AttrConfig> treeFlagList = new ArrayList<AttrConfig>();
        for (int i = 0; i < attrLst.size(); i++) {
            AttrConfig attrConfig = attrLst.get(i);
            String column = attrConfig.getAttrColumn().toLowerCase();
            String columnUpper = attrConfig.getAttrColumn();

            if ("selectList".equals(attrConfig.getAttrType())) {// 如果是下拉框的话
                selectFlag = true;
                //一开始只加载attrType是下拉框，module_type=1组件类型是关联关系的数据
                if ("add".equals(operType) || "treeTabAdd".equals(operType)) {
                    if ("1".equals(attrConfig.getModuleType())) {//---组件类型是关联关系
                        sb.append("    $http({ $RN$");
                        sb.append("          url : basePath+'/genJsp/getSelectData',$RN$");
                        sb.append("          method : 'POST', $RN$");
                        sb.append("          params : { $RN$");
                        if ("edit".equals(operType) || "treeTabEdit".equals(operType)) {//下拉框的值一开始生成的页面只加载数据库的一个值，其他的只有点击下拉框的时候才加载
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        } else if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "'$RN$");
                        } else {
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        }
                        sb.append("           } $RN$");
                        sb.append("        }).success(function(data, header, config, status) { $RN$");
                        sb.append("              $scope." + column + "s= data.data; $RN$");
                        sb.append("        }).error(function(data, header, config, status) { $RN$");
                        sb.append("              console.log('数据加载失败！'); $RN$");
                        sb.append("     }); $RN$");
                    } else if ("3".equals(attrConfig.getModuleType())) {//如果是选择设置的话
                        sb.append("    $http({ $RN$");
                        sb.append("          url : basePath+'/genJsp/getSelectData',$RN$");
                        sb.append("          method : 'POST', $RN$");
                        sb.append("          params : { $RN$");
                        if ("edit".equals(operType) || "treeTabEdit".equals(operType)) {//下拉框的值一开始生成的页面只加载数据库的一个值，其他的只有点击下拉框的时候才加载
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        } else if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "'$RN$");
                        } else {
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        }
                        sb.append("           } $RN$");
                        sb.append("        }).success(function(data, header, config, status) { $RN$");
                        sb.append("              $scope." + column + "s= data.data; $RN$");
                        sb.append("        }).error(function(data, header, config, status) { $RN$");
                        sb.append("              console.log('数据加载失败！'); $RN$");
                        sb.append("     }); $RN$");

                    }
                } else {
                    if ("1".equals(attrConfig.getModuleType())) {//---组件类型是关联关系
                        sb.append("       $http({ $RN$");
                        sb.append("             url : basePath+'/genJsp/getSelectData',$RN$");
                        sb.append("             method : 'POST', $RN$");
                        sb.append("             params : { $RN$");
                        if ("edit".equals(operType) || "treeTabEdit".equals(operType)) {//下拉框的值一开始生成的页面只加载数据库的一个值，其他的只有点击下拉框的时候才加载
                            sb.append("          'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        } else if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
                            sb.append("          'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        } else {
                            sb.append("          'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        }
                        sb.append("             } $RN$");
                        sb.append("           }).success(function(data, header, config, status) { $RN$");
                        sb.append("                 $scope." + column + "s= data.data; $RN$");
                        sb.append("           }).error(function(data, header, config, status) { $RN$");
                        sb.append("                 console.log('数据加载失败！'); $RN$");
                        sb.append("         }); $RN$");
                    } else if ("2".equals(attrConfig.getModuleType())) {//如果是级联下拉框
                        selectList.add(columnUpper);
                    } else if ("3".equals(attrConfig.getModuleType())) {//如果是选择设置的话
                        sb.append("    $http({ $RN$");
                        sb.append("          url : basePath+'/genJsp/getSelectData',$RN$");
                        sb.append("          method : 'POST', $RN$");
                        sb.append("          params : { $RN$");
                        if ("edit".equals(operType) || "treeTabEdit".equals(operType)) {//下拉框的值一开始生成的页面只加载数据库的一个值，其他的只有点击下拉框的时候才加载
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        } else if ("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)) {
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "'$RN$");
                        } else {
                            sb.append("            'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                        }
                        sb.append("           } $RN$");
                        sb.append("        }).success(function(data, header, config, status) { $RN$");
                        sb.append("              $scope." + column + "s= data.data; $RN$");
                        sb.append("        }).error(function(data, header, config, status) { $RN$");
                        sb.append("              console.log('数据加载失败！'); $RN$");
                        sb.append("     }); $RN$");

                    }
                }


            }

            // 如果是日期格式
            if ("DATE".equals(attrConfig.getAttrType())) {
                sb.append("    $('#" + column + "').datepicker({ $RN$");
                sb.append("            language: 'zh-CN', $RN$");
                sb.append("            autoclose: true, $RN$");
                sb.append("            clearBtn: true, $RN$");
                sb.append("            todayBtn: false, $RN$");
                sb.append("            todayHighlight: true, $RN$");
                sb.append("            format: 'yyyy-mm-dd' $RN$");
                sb.append("       }); $RN$");
            }

            // 如果是单选按钮
            if ("radioType".equals(attrConfig.getAttrType())) {// 如果是下拉框的话
                sb.append("     $http({ $RN$");
                sb.append("         url : basePath+'/genJsp/getSelectData', $RN$");
                sb.append("         method : 'POST', $RN$");
                sb.append("         params : { $RN$");
                sb.append("             'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                sb.append("         } $RN$");
                sb.append("       }).success(function(data, header, config, status) { $RN$");
                sb.append("          $scope." + column + "s= data.data; $RN$");
                sb.append("       }).error(function(data, header, config, status) { $RN$");
                sb.append("            console.log('数据加载失败！'); $RN$");
                sb.append("    }); $RN$");
            }

            // 如果是复选框
            if ("checkBoxType".equals(attrConfig.getAttrType())) {// 如果是下拉框的话
                checkBoxList.add(column);
                sb.append("       $http({ $RN$");
                sb.append("           url : basePath+'/genJsp/getSelectData', $RN$");
                sb.append("           method : 'POST', $RN$");
                sb.append("           params : { $RN$");
                sb.append("              'modelId' : '" + model.getId() + "','attrColumn':'" + columnUpper + "' $RN$");
                sb.append("           } $RN$");
                sb.append("         }).success(function(data, header, config, status) { $RN$");
                sb.append("             $scope." + column + "s= data.data; $RN$");
                sb.append("         }).error(function(data, header, config, status) { $RN$");
                sb.append("             console.log('数据加载失败！'); $RN$");
                sb.append("     }); $RN$");
            }

            // 如果是弹出框
            if ("popList".equals(attrConfig.getAttrType())) {
                popList.add(columnUpper);
                sb.append("       $scope.open" + column + " = function(){ $RN$")
                        .append("          $('#pop" + column + "').modal({")
                        .append("               remote: '" + tableName + "_" + columnUpper + "popList.jsp'  $RN$")
                        .append("          })  $RN$")
                        .append("}; $RN$");
                //添加  解决模态框的modal加载一次的问题
                sb.append("      $('#pop" + column + "').on(\"hidden.bs.modal\",function(){ $RN$"
                        + "         $(this).removeData(\"bs.modal\"); $RN$"
                        + "}); $RN$");
                if ("5".equals(attrConfig.getModuleType())) {
                    sb.append("       $scope.open" + column + "Clear = function(){ $RN$")
                            .append("           $('#" + column + "').val('');  $RN$")
                            .append("        }; $RN$");
                } else {
                    sb.append("       $scope.open" + column + "Clear = function(){ $RN$")
                            .append("           $('#" + column + "').val('');  $RN$")
                            .append("           $('#" + column + "Name').val('');  $RN$")
                            .append("        }; $RN$");
                }

            }

            // 如果是列表树
            if ("listTree".equals(attrConfig.getAttrType())) {
                treeFlagList.add(attrConfig);
                sb.append("      $scope.tree" + column + " = function(){ $RN$")
                        .append("         $('#tree" + column + "').modal({  $RN$")
                        .append("             remote: '" + tableName + "_" + columnUpper + "treeList.jsp'  $RN$")
                        .append("         })  $RN$")
                        .append("};$RN$");
                if ("1".equals(String.valueOf(attrConfig.getIsParentType()))) {//是父子树
                    if ("treeTabAdd".equals(operType)) {//如果是树模板新增
                        sb.append(" if($('#operColumn').val()=='" + column.toUpperCase() + "'){$RN$");
                        sb.append("       $http({  $RN$")
                                .append("            url : basePath+'/tree/getChildrenById', $RN$")
                                .append("            method : 'POST',$RN$")
                                .append("            params : { $RN$")
                                .append("                 tableName : '" + model.getTableName() + "',attrColumn:'" + column.toUpperCase() + "'," + column + ":$('#AddPid').val() $RN$")
                                .append("            } $RN$")
                                .append("         }).success(function(data, header, config, status) { $RN$")
                                .append("               if(data[0]!=null){ $RN$")
                                .append("                  $('#" + column + "').val(data[0].id); $RN$")
                                .append("                  $('#" + column + "Name').val(data[0].treeNodeName); $RN$")
                                .append("                  $scope." + column + "=data[0].id; $RN$")
                                .append("                  $scope." + column + "Name=data[0].treeNodeName; $RN$")
                                .append("                  $scope.pid=data[0].id; $RN$")
                                .append("               }else{ $RN$")
                                .append("                  $('#AddPid').val('0'); $RN$")
                                .append("                  $('#" + column + "Name').val('" + attrConfig.getViewName() + "'); $RN$")
                                .append("                  $('#" + column + "').val('0'); $RN$")
                                .append("                  $scope.pid='0'; $RN$")
                                .append("                  $scope." + column + "='0'; $RN$")
                                .append("               } $RN$")
                                .append("         }).error(function(data, header, config, status) { $RN$")
                                .append("                console.log('数据加载失败！'); $RN$")
                                .append("      }); $RN$");
                        sb.append("   } $RN$");
                    }

                    sb.append("     $scope.tree" + column + "Clear = function(){ $RN$")
                            //  .append("           $('#"+tableName+columnUpper+"treepid').val(''); $RN$")
                            //.append("           $('#"+column+"').val(''); $RN$")
                            .append("         $('#" + column + "').val('0');  $RN$")
                            .append("         $('#" + column + "Name').val('');  $RN$")
                            .append("         $scope." + column + " = 0;  $RN$")
                            .append("         $scope.pid = 0;  $RN$")
                            .append("      }; $RN$");
                    //}else{
//						sb.append("       $scope.tree" + column + "Clear = function(){ $RN$")
//						  .append("          $('#"+column+"').val('0');  $RN$")
//						  .append("          $('#"+column+"Name').val('');  $RN$")
//						  .append("          $scope."+column+" = 0;  $RN$")
//						  .append("      }; $RN$");
//					}
                } else {//是分类树
                    if ("treeTabAdd".equals(operType)) {//如果是树模板新增
                        if ("2".equals(model.getClassType())) {//是分类树
                            if ("1".equals(attrConfig.getClassColumn())) {//是关联属性
                                if (model.getClassColumn() != null) {
                                    sb.append("   if($('#AddColumn').val() !=null){ $RN$");
                                    sb.append("       $http({  $RN$")
                                            .append("            url : basePath+'/tree/getChildrenById', $RN$")
                                            .append("            method : 'POST',$RN$")
                                            .append("            params : { $RN$")
                                            .append("                 tableName : '" + TableConst.TABLEPREFIX + model.getMaintableId() + "',"
                                                    + "attrColumn:'" + attrConfig.getTreeViewColumn() + "',"
                                                    + attrConfig.getTreeViewColumn().toLowerCase() + ":$('#AddColumn').val() $RN$")
                                            .append("            } $RN$")
                                            .append("         }).success(function(data, header, config, status) { $RN$")
                                            .append("               if(data[0]!=null){ $RN$")
                                            .append("                  $('#" + column + "').val(data[0].id); $RN$")
                                            .append("                  $('#" + column + "Name').val(data[0].treeNodeName); $RN$")
                                            .append("                  $scope." + column + "=data[0].id; $RN$")
                                            .append("                  $scope." + column + "Name=data[0].treeNodeName; $RN$")
                                            .append("               } $RN$")
                                            .append("         }).error(function(data, header, config, status) { $RN$")
                                            .append("                console.log('数据加载失败！'); $RN$")
                                            .append("      }); $RN$");
                                    sb.append("   } $RN$");
                                }
                            }
                        }
                    }
                    sb.append("    $scope.tree" + column + "Clear = function(){ $RN$")
                            .append("       $('#" + column + "').val('');  $RN$")
                            .append("       $('#" + column + "Name').val('');  $RN$")
                            .append("     }; $RN$");
                }
            }
            //如果是文件类型
            if (attrConfig.getAttrType() != null && "BLOB".equals(attrConfig.getAttrType())) {
                //获取所有文件列
                fileList.add(column);
            }

            //如果是小数类型
            if ("NUMBERM".equals(attrConfig.getAttrType())) {
                sb.append("      $scope.check" + column + "Number = function(" + column + ") {   $RN$")
                        .append("         if(" + column + "){  $RN$")
                        .append("           if(" + column + ".indexOf('.')>0){  $RN$")
                        .append("             var attr = " + column + ".split('.');  $RN$")
                        .append("             var zs=attr[0];  $RN$")
                        .append("                if(zs.length>" + attrConfig.getAttrZs() + "){  $RN$")
                        .append("                    toastr.error('整数位长度过长,应小于或等于" + attrConfig.getAttrZs() + "位数!');   $RN$")
                        .append("                    $scope." + tableName + ".$valid=false;   $RN$")
                        .append("                    return false;  $RN$")
                        .append("                 }  $RN$")
                        .append("             var xs=attr[1];  $RN$")
                        .append("                if(xs.length>" + attrConfig.getAttrXs() + "){  $RN$")
                        .append("                     toastr.error('小数位长度过长,应小于或等于" + attrConfig.getAttrXs() + "位数!');   $RN$")
                        .append("                     $scope." + tableName + ".$valid=false;   $RN$")
                        .append("                     return false;  $RN$")
                        .append("                 }  $RN$")
                        .append("            }else{//说明没有小数点  $RN$")
                        .append("               if(" + column + ".length>" + attrConfig.getAttrZs() + "){  $RN$")
                        .append("                     toastr.error('整数位长度过长,应小于或等于" + attrConfig.getAttrZs() + "位数!');   $RN$")
                        .append("                     $scope." + tableName + ".$valid=false;   $RN$")
                        .append("                     return false;  $RN$")
                        .append("                 }  $RN$")
                        .append("             }  $RN$")
                        .append("        }$RN$")
                        .append("     }  $RN$");
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("sb", sb.toString().replace("$RN$", "\r\n"));
        map.put("checkboxList", checkBoxList);
        map.put("popList", popList);
        map.put("treeFlagList", treeFlagList);
        map.put("selectFlag", selectFlag);
        map.put("selectList", selectList);
        map.put("fileFlag", fileList);
        return map;
    }

    //新增页面必填项提示
    public static String checkColumnsAdd(Model model, List<AttrConfig> jspAttrLst, List<AttrGroup> groupLst, String operType) {
        StringBuilder sb = new StringBuilder();
        List<AttrConfig> checkAttrLst = new ArrayList<AttrConfig>();
        List<AttrConfig> nGroupLst = new ArrayList<AttrConfig>();
        //获取在新增页面必填的列

        for (int j = 0; j < jspAttrLst.size(); j++) {
            AttrConfig attrConfig = jspAttrLst.get(j);
            if (0 == attrConfig.getIsNull()) {//查询所有必填项
                checkAttrLst.add(attrConfig);
            }
        }
        for (int i = 0; i < checkAttrLst.size(); i++) {
            AttrConfig attrConfig1 = checkAttrLst.get(i);
            if (attrConfig1.getGroupId() == null || attrConfig1.getGroupId().equals("")) {
                nGroupLst.add(attrConfig1);
            }
        }

        if (model.getIsMoreView() == 1) {//表示是多视图
            if (groupLst.size() > 0) {
                for (int i = 0; i < groupLst.size(); i++) {
                    AttrGroup attrGroup = groupLst.get(i);
                    String groupId = attrGroup.getId().toString();
                    if (attrGroup.getIsDefaultView() != 1) {//不是默认属性
                        sb.append("  if ($('#" + model.getTableName() + "_" + groupId + "').is(':checked')) {$RN$");
                        for (int j = 0; j < checkAttrLst.size(); j++) {
                            AttrConfig attrConfig = checkAttrLst.get(j);
                            String column = attrConfig.getAttrColumn().toLowerCase();//列名
                            String attrName = attrConfig.getAttrName();//属性名称
                            if (groupId.equals(attrConfig.getGroupId())) {//如果是这个属性组下的属性
                                if (attrConfig.getAttrType() != null && ("VARCHAR2".equals(attrConfig.getAttrType()) || "DATE".equals(attrConfig.getAttrType())
                                        || "CLOB".equals(attrConfig.getAttrType()) || "BLOB".equals(attrConfig.getAttrType())
                                        || "selectList".equals(attrConfig.getAttrType())
                                        || "listTree".equals(attrConfig.getAttrType()))) {//如果是输入框
                                    sb.append("  $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                                    sb.append("      if (!$scope." + column + ") {$RN$")
                                            .append("           toastr.warning('" + attrName + "不可为空！');$RN$")
                                            .append("           formValid = false;$RN$")
                                            .append("         return false;$RN$")
                                            .append("      }$RN$");
                                } else if ("radioType".equals(attrConfig.getAttrType()) || "checkBoxType".equals(attrConfig.getAttrType())) {
                                    sb.append("   $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                                    sb.append("     if (!$scope." + column + ") {$RN$")
                                            .append("          toastr.warning('" + attrName + "不可为空！');$RN$")
                                            .append("          formValid = false;$RN$")
                                            .append("          return false;$RN$")
                                            .append("      }$RN$");
                                } else {
                                    sb.append("   $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                                    sb.append("     if (!$scope." + column + ") {$RN$")
                                            .append("         toastr.warning('" + attrName + "不可为空！');$RN$")
                                            .append("         formValid = false;$RN$")
                                            .append("         return false;$RN$")
                                            .append("      }$RN$");
                                }
                            }
                        }
                        sb.append("  }$RN$");
                    } else {//表示是默认属性组（默认属性组的必填属性字段，必须校验）

                        for (int j = 0; j < checkAttrLst.size(); j++) {
                            AttrConfig attrConfig = checkAttrLst.get(j);
                            String column = attrConfig.getAttrColumn().toLowerCase();//列名
                            String attrName = attrConfig.getAttrName();//属性名称
                            if (groupId.equals(attrConfig.getGroupId())) {//如果是这个属性组下的属性
                                if ("VARCHAR2".equals(attrConfig.getAttrType()) || "DATE".equals(attrConfig.getAttrType())
                                        || "CLOB".equals(attrConfig.getAttrType()) || "BLOB".equals(attrConfig.getAttrType())
                                        || "selectList".equals(attrConfig.getAttrType())
                                        || "listTree".equals(attrConfig.getAttrType())) {//如果是输入框
                                    sb.append("  $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                                    sb.append("      if (!$scope." + column + ") {$RN$")
                                            .append("           toastr.warning('" + attrName + "不可为空！');$RN$")
                                            .append("           formValid = false;$RN$")
                                            .append("         return false;$RN$")
                                            .append("      }$RN$");
                                } else if ("radioType".equals(attrConfig.getAttrType()) || "checkBoxType".equals(attrConfig.getAttrType())) {
                                    sb.append("   $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                                    sb.append("     if (!$scope." + column + ") {$RN$")
                                            .append("          toastr.warning('" + attrName + "不可为空！');$RN$")
                                            .append("          formValid = false;$RN$")
                                            .append("          return false;$RN$")
                                            .append("      }$RN$");
                                } else {
                                    sb.append("   $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                                    sb.append("     if (!$scope." + column + ") {$RN$")
                                            .append("         toastr.warning('" + attrName + "不可为空！');$RN$")
                                            .append("         formValid = false;$RN$")
                                            .append("         return false;$RN$")
                                            .append("      }$RN$");
                                }
                            }
                        }
                    }
                }
            }
            if (nGroupLst.size() > 0) {
                for (int m = 0; m < nGroupLst.size(); m++) {
                    AttrConfig attrConfig = nGroupLst.get(m);
                    String column = attrConfig.getAttrColumn().toLowerCase();//列名
                    String attrName = attrConfig.getAttrName();//属性名称
                    if (attrConfig.getAttrType() != null && ("VARCHAR2".equals(attrConfig.getAttrType()) || "DATE".equals(attrConfig.getAttrType())
                            || "CLOB".equals(attrConfig.getAttrType()) || "BLOB".equals(attrConfig.getAttrType())
                            || "selectList".equals(attrConfig.getAttrType()) || "listTree".equals(attrConfig.getAttrType()))) {//如果是输入框
                        sb.append("   $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                        sb.append("      if (!$scope." + column + ") {$RN$")
                                .append("           toastr.warning('" + attrName + "不可为空！');$RN$")
                                .append("           formValid = false;$RN$")
                                .append("         return false;$RN$")
                                .append("      }$RN$");
                    } else if ("radioType".equals(attrConfig.getAttrType()) || "checkBoxType".equals(attrConfig.getAttrType())) {
                        sb.append("    $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                        sb.append("     if (!$scope." + column + ") {$RN$")
                                .append("          toastr.warning('" + attrName + "不可为空！');$RN$")
                                .append("          formValid = false;$RN$")
                                .append("          return false;$RN$")
                                .append("      }$RN$");
                    } else {
                        sb.append("    $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                        sb.append("     if (!$scope." + column + ") {$RN$")
                                .append("         toastr.warning('" + attrName + "不可为空！');$RN$")
                                .append("         formValid = false;$RN$")
                                .append("         return false;$RN$")
                                .append("      }$RN$");
                    }
                }
            }
        } else {
            for (int i = 0; i < checkAttrLst.size(); i++) {
                AttrConfig attrConfig = checkAttrLst.get(i);
                String column = attrConfig.getAttrColumn().toLowerCase();//列名
                String attrName = attrConfig.getAttrName();//属性名称
                if (attrConfig.getAttrType() != null && ("VARCHAR2".equals(attrConfig.getAttrType()) || "DATE".equals(attrConfig.getAttrType())
                        || "CLOB".equals(attrConfig.getAttrType()) || "BLOB".equals(attrConfig.getAttrType())
                        || "selectList".equals(attrConfig.getAttrType()) || "listTree".equals(attrConfig.getAttrType()))) {//如果是输入框
                    sb.append("   $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                    sb.append("      if (!$scope." + column + ") {$RN$")
                            .append("           toastr.warning('" + attrName + "不可为空！');$RN$")
                            .append("           formValid = false;$RN$")
                            .append("         return false;$RN$")
                            .append("      }$RN$");
                } else if ("radioType".equals(attrConfig.getAttrType()) || "checkBoxType".equals(attrConfig.getAttrType())) {
                    sb.append("    $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                    sb.append("     if (!$scope." + column + ") {$RN$")
                            .append("          toastr.warning('" + attrName + "不可为空！');$RN$")
                            .append("          formValid = false;$RN$")
                            .append("          return false;$RN$")
                            .append("      }$RN$");
                } else {
                    sb.append("    $scope." + column + " = angular.element($('#" + column + "')).val();$RN$");
                    sb.append("     if (!$scope." + column + ") {$RN$")
                            .append("         toastr.warning('" + attrName + "不可为空！');$RN$")
                            .append("         formValid = false;$RN$")
                            .append("         return false;$RN$")
                            .append("      }$RN$");
                }
            }
        }

        return sb.toString().replace("$RN$", "\r\n");
    }
    //判断是否含有唯一校验
//	public static String checkColumnIsShow(List<AttrConfig> jspAttrLst){
//		StringBuilder sb =new StringBuilder();
//		List<AttrConfig> checkAttrLst  = new ArrayList<AttrConfig>();
//		for (int i = 0; i < jspAttrLst.size(); i++) {
//			AttrConfig attrConfig = jspAttrLst.get(i);
//			String ruleType = attrConfig.getRuleType();
//			if(ruleType!=null){
//				if(ruleType.equals("0")){//唯一校验的列
//					checkAttrLst.add(attrConfig);
//				}
//			}
//		}
//		for (int i = 0; i < checkAttrLst.size(); i++) {
//			  AttrConfig attrConfig = checkAttrLst.get(i);
//		  	  String column = attrConfig.getAttrColumn().toLowerCase();//列名
//				sb.append("  $scope.check"+column+"Name = false; $RN$");
//		}
//		return sb.toString().replace("$RN$", "\r\n");
//	}

    //	public static String checkWeiYiColumn(List<AttrConfig> jspAttrLst,Model model,String operType){
//		StringBuilder sb =new StringBuilder();
//		List<AttrConfig> checkAttrLst  = new ArrayList<AttrConfig>();
//		for (int i = 0; i < jspAttrLst.size(); i++) {
//			AttrConfig attrConfig = jspAttrLst.get(i);
//			String ruleType = attrConfig.getRuleType();
//			if(ruleType!=null){
//				if(ruleType.equals("0")){//唯一校验的列
//					checkAttrLst.add(attrConfig);
//				}
//			}
//		}
//		if(checkAttrLst.size()>0){
//			sb.append("function checkColumnWeiYiName(){$RN$");
//			sb.append("var result = true;$RN$");
//			for (int i = 0; i < checkAttrLst.size(); i++) {
//				AttrConfig attrConfig = checkAttrLst.get(i);
//				String column = attrConfig.getAttrColumn().toLowerCase();//列名
//				if("edit".equals(operType) || "treeTabEdit".equals(operType)){
//					sb.append("   $http({$RN$")
//				    .append("       url : basePath+'/jspAction/checkcolumnName',$RN$")
//				    .append("       method : 'POST',$RN$")
//				    .append("       params : {$RN$")
//				    .append("           'tableName' : "+model.getTableName()+",$RN$")
//				    .append("           'column' : "+column+",$RN$")
//				    .append("           'value' : $scope."+column+",$RN$")
//				    .append("           'id' : $scope.id $RN$")
//				    .append("       }$RN$")
//				    .append("      }).success(function(data, header, config, status) {$RN$")
//				    .append("         var count = angular.fromJson(data).rmsg.rspCode;$RN$")
//				    .append("         if (count > '0') { // 没有重复$RN$")
//				    .append("            $scope.check"+column+"Name = true; $RN$")
//				    .append("               result = false;$RN$")
//				    .append("               return false;$RN$")
//				    .append("         }$RN$")
//				    .append("     }).error(function(data, header, config, status) {$RN$")
//				    .append("              result = false;$RN$")
//				    .append("               return false;$RN$")
//				    .append("  });$RN$");
//				}else if("updateEdit".equals(operType) || "treeTabUpdateEdit".equals(operType)){
//					sb.append("   $http({$RN$")
//				    .append("       url : basePath+'/jspAction/checkcolumnName',$RN$")
//				    .append("       method : 'POST',$RN$")
//				    .append("       params : {$RN$")
//				    .append("           'tableName' : "+model.getTableName()+",$RN$")
//				    .append("           'column' : "+column+",$RN$")
//				    .append("           'value' : $scope."+column+",$RN$")
//				    .append("           'id' : $scope.updateId $RN$")
//				    .append("       }$RN$")
//				    .append("      }).success(function(data, header, config, status) {$RN$")
//				    .append("         var count = angular.fromJson(data).rmsg.rspCode;$RN$")
//				    .append("         if (count > '0') { // 没有重复$RN$")
//				    .append("            $scope.check"+column+"Name = true; $RN$")
//				    .append("               result = false;$RN$")
//				    .append("               return false;$RN$")
//				    .append("         }$RN$")
//				    .append("     }).error(function(data, header, config, status) {$RN$")
//				    .append("              result = false;$RN$")
//				    .append("               return false;$RN$")
//				    .append("  });$RN$");
//				}else{
//					sb.append("   $http({$RN$")
//				    .append("       url : basePath+'/jspAction/checkcolumnName',$RN$")
//				    .append("       method : 'POST',$RN$")
//				    .append("       params : {$RN$")
//				    .append("           'tableName' : "+model.getTableName()+",$RN$")
//				    .append("           'value' : $scope."+column+",$RN$")
//				    .append("           'column' : "+column+"$RN$")
//				    .append("       }$RN$")
//				    .append("      }).success(function(data, header, config, status) {$RN$")
//				    .append("         var count = angular.fromJson(data).rmsg.rspCode;$RN$")
//				    .append("         if (count > '0') { // 没有重复$RN$")
//				    .append("            $scope.check"+column+"Name = true; $RN$")
//				    .append("               result = false;$RN$")
//				    .append("               return false;$RN$")
//				    .append("         }$RN$")
//				    .append("     }).error(function(data, header, config, status) {$RN$")
//				    .append("              result = false;$RN$")
//				    .append("               return false;$RN$")
//				    .append("  });$RN$");
//				}
//				  
//			}
//			sb.append("}$RN$");
//		}
//		return sb.toString().replace("$RN$", "\r\n");
//	}
    //拼写唯一性校验的列及方法
    public static String spellWeiYiMethod(List<AttrConfig> jspAttrLst) {
        StringBuilder sb = new StringBuilder();
        List<AttrConfig> checkAttrLst = new ArrayList<AttrConfig>();
        for (int i = 0; i < jspAttrLst.size(); i++) {
            AttrConfig attrConfig = jspAttrLst.get(i);
            String ruleType = attrConfig.getRuleType();
            String ruleTypeId = attrConfig.getRuleTypeId();
//			if(ruleType!=null && ruleTypeId!=null){
            if (!StringUtils.isEmpty(ruleType)) {
                if (ruleType.equals("0")) {//唯一校验的列
                    checkAttrLst.add(attrConfig);
                }
            }
        }
        sb.append("checkParams : '");
        if (checkAttrLst.size() > 0) {
            String usb = "";
            for (int i = 0; i < checkAttrLst.size(); i++) {
                AttrConfig ac = checkAttrLst.get(i);
                String column = ac.getAttrColumn().toLowerCase();
//				usb=usb+column+":'+data[i]."+column+"+'@";
                //这块逻辑要改成动态读取ConstantBean.java里面的配置
                usb = usb + column + ":'+data[i]." + column + "+'" + ConstantBean.REPLACE_AT_FH;
            }
            usb = usb.substring(0, usb.length() - 2 - ConstantBean.REPLACE_AT_FH.length());
//			usb=usb.substring(0,usb.length()-3);
            sb.append(usb);
            sb.append(",$RN$");
        } else {
            sb.append(" ',$RN$");
        }
        return sb.toString().replace("$RN$", "\r\n");
    }

    //多视图新增，编辑，js
    public static String getIsMoreViewApply(Model model, List<AttrGroup> groupLst) {
        StringBuilder sb = new StringBuilder();
        if (groupLst.size() > 0) {
            if (model.getIsMoreView() == 1) {//表示多视图模型
                for (int i = 0; i < groupLst.size(); i++) {
                    AttrGroup attrGroup = groupLst.get(i);
                    String groupID = attrGroup.getId();//获取groupID
                    if (attrGroup.getIsDefaultView() != 1) {//不是默认显示
                        sb.append("  if ($('#" + model.getTableName() + "_" + groupID + "').is(':checked')) {$RN$");
                        sb.append("      $scope." + model.getTableName() + "_" + groupID + " = true;$RN$");
                        sb.append("  }else{$RN$");
                        sb.append("      $scope." + model.getTableName() + "_" + groupID + " = false;$RN$");
                        sb.append("  }$RN$");

                        sb.append("  $scope.check_" + model.getTableName() + "_" + groupID + "_Check = function(){$RN$");
                        sb.append("     if ($('#" + model.getTableName() + "_" + groupID + "').is(':checked')) {$RN$");
                        sb.append("         $scope." + model.getTableName() + "_" + groupID + " = true;$RN$");
                        sb.append("     }else{$RN$");
                        sb.append("         $scope." + model.getTableName() + "_" + groupID + " = false;$RN$");
                        sb.append("     }$RN$");
                        sb.append("  }$RN$");
                    } else {
                        sb.append("      $scope." + model.getTableName() + "_" + groupID + " = true;$RN$");
                    }
                }

            } else {
                sb.append(" $RN$");
            }
        } else {
            sb.append(" $RN$");
        }
        return sb.toString().replace("$RN$", "\r\n");

    }

    //提交时，动态判断属性是否可显示
    public static String getIsMoreClearAttrs(Model model, List<AttrGroup> groupLst, List<AttrConfig> jspAttrLst) {
        StringBuilder sb = new StringBuilder();
        if (groupLst.size() > 0) {
            if (model.getIsMoreView() == 1) {//表示多视图模型
                // String groupIds = "";
                sb.append("         var   groupIds='';  $RN$");
                for (int i = 0; i < groupLst.size(); i++) {
                    AttrGroup attrGroup = groupLst.get(i);
                    if (attrGroup.getIsDefaultView() != 1) {//不是默认显示
                        String groupID = attrGroup.getId();//获取groupID
                        sb.append("  if ($('#" + model.getTableName() + "_" + groupID + "').is(':checked')) {$RN$");
                        sb.append("            groupIds=groupIds+" + groupID + "+'_1,';  $RN$");

                        sb.append("  }else{$RN$");
                        sb.append("            groupIds=groupIds+" + groupID + "+'_0,';  $RN$");

                        for (int j = 0; j < jspAttrLst.size(); j++) {
                            AttrConfig attrConfig = jspAttrLst.get(j);
                            String column = attrConfig.getAttrColumn().toLowerCase();
                            if (groupID.equals(attrConfig.getGroupId())) {
                                if ("popList".equals(attrConfig.getAttrType())) {//如果是弹出框
                                    if ("5".equals(attrConfig.getModuleType())) {
                                        sb.append("           $('#" + column + "').val('');  $RN$");
                                        sb.append("           $scope." + column + "= null;$RN$");
                                    } else {
                                        sb.append("           $('#" + column + "').val('');  $RN$");
                                        sb.append("           $('#" + column + "Name').val('');  $RN$");
                                        sb.append("           $scope." + column + "= null;$RN$");
                                    }
                                } else if ("listTree".equals(attrConfig.getAttrType())) {
                                    if ("1".equals(String.valueOf(attrConfig.getIsParentType()))) {//是父子树
                                        sb.append("           $('#" + model.getTableName() + attrConfig.getAttrColumn() + "treepid').val(''); $RN$");
                                        sb.append("           $('#" + column + "').val(''); $RN$");
                                        sb.append("           $scope.pid = null;  $RN$");
                                    } else {//是分类树
                                        if ("2".equals(model.getClassType())) {//是分类树
                                            sb.append("       $('#" + column + "').val('');  $RN$");
                                            sb.append("       $('#" + column + "Name').val('');  $RN$");
                                            sb.append("       $scope." + column + "= null;$RN$");
                                        } else {
                                            sb.append("       $('#" + column + "').val('');  $RN$");
                                            sb.append("       $('#" + column + "Name').val('');  $RN$");
                                            sb.append("       $scope." + column + "= null;$RN$");
                                        }
                                    }
                                } else {//其它类型
                                    sb.append("       $('#" + column + "').val('');$RN$");
                                    sb.append("       $scope." + column + "= null;$RN$");
                                }
                            }
                        }
                        sb.append("  }$RN$");
                    } else {
                        String groupID = attrGroup.getId();//获取groupID
                        sb.append("            groupIds=groupIds+" + groupID + "+'_1,';  $RN$");
                    }
                }
                //groupIds = groupIds.substring(0,groupIds.length()-1);
//			if(groupIds!=""){
//				sb.append("         var  groupIds = '"+groupIds+"';  $RN$");
//			}
            }
        }
        return sb.toString().replace("$RN$", "\r\n");
    }


    //多视图新增，编辑，js
    public static String dataViewEditSource(Model model, String operType, List<AttrGroup> groupLst) {
        StringBuilder sb = new StringBuilder();
        if (groupLst.size() > 0) {
            if (model.getIsMoreView() == 1) {//表示多视图模型
                if ("treeTabEdit".equals(operType) || "edit".equals(operType)) {
                    sb.append("        $http({$RN$");
                    sb.append("            url : basePath+'/jspAction/queryDataViewFlows',$RN$");
                    sb.append("            method : 'POST',$RN$");
                    sb.append("            params : {$RN$");
                    sb.append("              'modelId'  : '" + model.getId() + "',$RN$");
                    sb.append("              'dataId'  : $scope.id $RN$ ");
                    sb.append("            }$RN$");
                    sb.append("         }).success(function(data, header, config, status) {$RN$");
                    sb.append("             if(data!=null){ $RN$");
                    sb.append("                 for (var i = 0; i < data.length; i++) { $RN$");
                    sb.append("                      var t_data = data[i]; $RN$");
                    sb.append("                        if(t_data.isSelected == '1'){//选中状态 $RN$");
                    for (int i = 0; i < groupLst.size(); i++) {
                        AttrGroup attrGroup = groupLst.get(i);
                        String groupID = attrGroup.getId();//获取groupID
                        if (attrGroup.getIsDefaultView() != 1) {//不是默认显示
                            sb.append("                        if(t_data.groupId == " + groupID + "){//选中状态 $RN$");
                            sb.append("                           $('#" + model.getTableName() + "_" + groupID + "').prop('checked',true); $RN$");
                            sb.append("                           $scope." + model.getTableName() + "_" + groupID + " = true; $RN$");
                            sb.append("                          }$RN$");
                        }
                    }
                    sb.append("                         }$RN$");
                    sb.append("                     }$RN$");
                    sb.append("              }$RN$");
                    sb.append("         }).error(function(data, header, config, status) {$RN$");

                    sb.append("         });   $RN$");
                } else if ("treeTabUpdateEdit".equals(operType) || "updateEdit".equals(operType)) {

                    sb.append("        $http({$RN$");
                    sb.append("            url : basePath+'/jspAction/queryDataViewFlows',$RN$");
                    sb.append("            method : 'POST',$RN$");
                    sb.append("            params : {$RN$");
                    sb.append("              'modelId'  : '" + model.getId() + "',$RN$");
                    sb.append("              'dataId'  : $scope.originId $RN$ ");
                    sb.append("            }$RN$");
                    sb.append("         }).success(function(data, header, config, status) {$RN$");
                    sb.append("             if(data!=null){ $RN$");
                    sb.append("                 for (var i = 0; i < data.length; i++) { $RN$");
                    sb.append("                      var t_data = data[i]; $RN$");
                    sb.append("                        if(t_data.isSelected == '1'){//选中状态 $RN$");
                    for (int i = 0; i < groupLst.size(); i++) {
                        AttrGroup attrGroup = groupLst.get(i);
                        String groupID = attrGroup.getId();//获取groupID
                        if (attrGroup.getIsDefaultView() != 1) {//不是默认显示
                            sb.append("                        if(t_data.groupId == " + groupID + "){//选中状态 $RN$");
                            sb.append("                           $('#" + model.getTableName() + "_" + groupID + "').prop('checked',true); $RN$");
                            sb.append("                           $scope." + model.getTableName() + "_" + groupID + " = true; $RN$");
                            sb.append("                          }$RN$");
                        }
                    }
                    sb.append("                         }$RN$");
                    sb.append("                     }$RN$");
                    sb.append("              }$RN$");
                    sb.append("         }).error(function(data, header, config, status) {$RN$");

                    sb.append("         });   $RN$");
                }
            } else {
                sb.append("$RN$");
            }
        } else {
            sb.append("$RN$");
        }
        return sb.toString().replace("$RN$", "\r\n");

    }

}
